package logic

import (
	"context"
	"order-pro/model"

	"order-pro/prorpc/internal/svc"
	"order-pro/prorpc/prorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAddLogic {
	return &OrderAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderAddLogic) OrderAdd(in *prorpc.OrderAddRequest) (*prorpc.OrderAddResponse, error) {
	// todo: add your logic here and delete this line
	var order model.Order
	total := 0.0

	subTotal := order.SubTotal * order.Price
	total += subTotal
	orders := model.Order{
		Name:     in.Name,
		Price:    float64(in.Price),
		Content:  in.Content,
		Quantidy: in.Quantidy,
		SubTotal: float64(in.SubTotal),
	}
	model.DB.Create(&orders)

	return &prorpc.OrderAddResponse{
		OrderID: int64(orders.ID),
	}, nil
}
